﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc;

namespace WaiGaoQiaoWeb.Controllers
{
    public class ExcelContentResult : ContentResult
    {
        public string filename
        {
            get;
            set;
        }
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.Clear();
            context.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".xls");
            context.HttpContext.Response.ContentType = "application/ms-excel";
            context.HttpContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");  //GB2312
            context.HttpContext.Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
            context.HttpContext.Response.Write("</head><body>");
            context.HttpContext.Response.Write(Content.ToString());
            context.HttpContext.Response.Write("</body></html>");
            context.HttpContext.Response.End();
        }
    }
}